package com.lambkit.component.shiro;

import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.session.mgt.eis.SessionDAO;

import com.jfinal.kit.StrKit;
import com.lambkit.Lambkit;
import com.lambkit.component.shiro.cache.RedisCacheManager;
import com.lambkit.component.shiro.session.ShiroSessionDAO;

public class DefaultLambkitShiroConfigService extends AbstractLambkitShiroConfigService {

	@Override
	public SessionDAO createShiroSessionDao() {
		// TODO Auto-generated method stub
		return new ShiroSessionDAO();
	}

	@Override
	public Realm createRealm() {
		// TODO Auto-generated method stub
		ShiroConfig shiroConfig = Lambkit.config(ShiroConfig.class);
		if (StrKit.notBlank(shiroConfig.getRealm())) {
			Realm realm = Lambkit.get(shiroConfig.getRealm());
			return realm;
		}
		return null;
	}

	@Override
	public CacheManager createCacheManager() {
		// TODO Auto-generated method stub
		// cahce---org.apache.shiro.cache.MemoryConstrainedCacheManager
		// cacheManager=org.apache.shiro.cache.ehcache.EhCacheManager
		// cacheManager.cacheManagerConfigFile=classpath:ehcache.xml
		RedisCacheManager cacheManager = new RedisCacheManager();
		return cacheManager;
	}

}
